﻿namespace LearnDSRecursions;

public class Recursion
{
    public void Calculateiteratve(int n)
    {
        while (n > 0)
        {
            int k = n * n;
            Console.WriteLine(k);
            n = n - 1;
        }
    }

    public void Calculaterecursive(int n)
    {
        if (n > 0)
        {
            int k = n * n;
            Console.WriteLine(k);
            Calculaterecursive(n - 1);
        }
    }

    /// <summary>
    /// 头递归
    /// </summary>
    /// <param name="n"></param>
    public void HeadRecursion(int n)
    {
        if (n > 0)
        {
            HeadRecursion(n - 1);
            int k = n * n;
            Console.WriteLine(k);
        }
    }

    /// <summary>
    /// 尾递归
    /// </summary>
    /// <param name="n"></param>
    public void TailRecursion(int n)
    {
        if (n > 0)
        {
            int k = n * n;
            Console.WriteLine(k);
            TailRecursion(n - 1);
        }
    }

    /// <summary>
    /// 树递归
    /// </summary>
    /// <param name="n"></param>
    public void TreeRecursion(int n)
    {
        if (n > 0)
        {
            TreeRecursion(n - 1);
            int k = n * n;
            Console.WriteLine(k);
            TreeRecursion(n - 1);
        }
    }
}